package com.biaobiaoqi.scoreanalysis.serviceImpl;

import java.util.List;

import com.biaobiaoqi.scoreanalysis.exception.DuplicateClazzTypeException;
import com.biaobiaoqi.scoreanalysis.exception.NoSuchClazzTypeFoundException;
import com.biaobiaoqi.scoreanalysis.hibernate.bean.ClazzType;
import com.biaobiaoqi.scoreanalysis.service.IClazzTypeService;

//@Service
//@Transactional(rollbackFor=Exception.class)
public class ClazzTypeServiceImpl extends DaoServiceImpl<ClazzType> implements IClazzTypeService{

	@Override
	public void addClazzType(String type) throws DuplicateClazzTypeException {
		if (findClazzType(type)!=null) {
			throw new DuplicateClazzTypeException();
		}
		ClazzType clazzType = new ClazzType();
		clazzType.setClazzType(type);
		getDao().create(clazzType);
	}

	@Override
	public void deleteClazzType(String type) throws NoSuchClazzTypeFoundException {
		ClazzType clazzType = findClazzType(type);
		if (clazzType==null) {
			throw new NoSuchClazzTypeFoundException();
		}
		getDao().delete(clazzType);
	}

	@Override
	public List<ClazzType> listClazzType() {
		return getDao().queryList("from ClazzType c");
	}

	@Override
	public List<ClazzType> listClazzType(int from, int number) {
		return getDao().queryList("from ClazzType c", from, number);
	}

	@Override
	public ClazzType findClazzType(String type) {
		return getDao().queryUnique("from ClazzType c where c.clazzType=?", type);
	}
	
	@Override
	public ClazzType findClazzType(int typeId) {
		return getDao().findById(ClazzType.class, typeId);
	}

	@Override
	public void deleteClazzType(int typeId) {
		getDao().delete(findClazzType(typeId));
	}

}
